//
//  TitleButton.m
//  CD1505WeiBo
//
//  Created by 千锋 on 15/12/30.
//  Copyright (c) 2015年 LiChaoRan. All rights reserved.
//

#import "TitleButton.h"

@implementation TitleButton

- (instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        _ratio=0.8;
        self.titleLabel.textAlignment=NSTextAlignmentCenter;
        self.imageView.contentMode=UIViewContentModeCenter;
    }
    return self;
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    CGFloat imgX=_ratio*CGRectGetWidth(contentRect);
    CGFloat imgY=0;
    CGFloat imgW=(1-_ratio)*CGRectGetWidth(contentRect);
    CGFloat imgH=CGRectGetHeight(contentRect);
    NSLog(@"");
    
    return CGRectMake(imgX, imgY, imgW, imgH);
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleX=0;
    CGFloat titleY=0;
    CGFloat titleW=CGRectGetWidth(contentRect)*_ratio;
    CGFloat titleH=CGRectGetHeight(contentRect);
    
    return CGRectMake(titleX, titleY, titleW, titleH);
}

@end
